/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pclong.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestThreadPool {

    /** 
     * @param args 
     */
    public static void main(String[] args) {

        // 创建线程池  
        ExecutorService exec = Executors.newFixedThreadPool(3);

        // 建立100个线程  
        for (int index = 0; index < 10; index++) {
            Runnable run = new Runnable() {

                public void run() {

                    // 随机毫秒  
                    long time = (long) (Math.random() * 500);
                    System.out.println("Sleeping "
                            + Thread.currentThread().getName() + ":" + time
                            + "ms");
                    try {
                        Thread.sleep(time);

                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            };

            //执行  
            exec.execute(run);
        }

        //关闭  
        exec.shutdown();

    }
}
